/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 1997-2013 Oracle and/or its affiliates. All rights reserved.
 *
 * The contents of this file are subject to the terms of either the GNU
 * General Public License Version 2 only ("GPL") or the Common Development
 * and Distribution License("CDDL") (collectively, the "License").  You
 * may not use this file except in compliance with the License.  You can
 * obtain a copy of the License at
 * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
 * or packager/legal/LICENSE.txt.  See the License for the specific
 * language governing permissions and limitations under the License.
 *
 * When distributing the software, include this License Header Notice in each
 * file and include the License file at packager/legal/LICENSE.txt.
 *
 * GPL Classpath Exception:
 * Oracle designates this particular file as subject to the "Classpath"
 * exception as provided by Oracle in the GPL Version 2 section of the License
 * file that accompanied this code.
 *
 * Modifications:
 * If applicable, add the following below the License Header, with the fields
 * enclosed by brackets [] replaced by your own identifying information:
 * "Portions Copyright [year] [name of copyright owner]"
 *
 * Contributor(s):
 * If you wish your version of this file to be governed by only the CDDL or
 * only the GPL Version 2, indicate your decision by adding "[Contributor]
 * elects to include this software in this distribution under the [CDDL or GPL
 * Version 2] license."  If you don't indicate a single choice of license, a
 * recipient has the option to distribute your version of this file under
 * either the CDDL, the GPL Version 2 or to extend the choice of license to
 * its licensees as provided above.  However, if you add GPL Version 2 code
 * and therefore, elected the GPL Version 2 license, then the option applies
 * only if the new code is made subject to such option by the copyright
 * holder.
 */

package interceptor;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Map;

/**
 * <p>
 *     公开被截获的调用和操作的上下文信息，这些信息使拦截器方法能够控制调用链的行为.
 * </p>
 * 例子如下：
 * <pre>
 *
 *    &#064;AroundInvoke
 *    public Object logInvocation(InvocationContext ctx) throws Exception {
 *       String class = ctx.getMethod().getDeclaringClass().getName();
 *       String method = ctx.getMethod().getName();
 *       Logger.global.entering(class, method, ctx.getParameters());
 *       try {
 *          Object result = ctx.proceed();
 *          Logger.global.exiting(class, method, result);
 *          return result;
 *       }
 *       catch (Exception e) {
 *          Logger.global.throwing(class, method, e);
 *          throw e;
 *       }
 *
 *    }
 * 
 * </pre>
 *
 * @since Interceptors 1.0
 */
public interface InvocationContext {

    /**
     * 返回目标实例.在{@link #proceed}方法调用前调用getTarget方法，则返回null
     *
     * @return 目标实例
     */
    public Object getTarget();

    /**
     * 返回与目标类上的超时方法调用关联的计时器对象，或方法和生命周期回调拦截器方法的空值(ps:感觉不会常用)
     *
     * @return timer对象 / null
     *
     * @since Interceptors 1.1
     */
    public Object getTimer();

    /**
     * 返回被调用类上的方法.
     *
     * @return the method, or a null value
     */
    public Method getMethod();

    /**
     * 返回被调用类上的构造方法
     *
     * @return the constructor, or a null value
     */
    public Constructor<?> getConstructor();

    /**
     * 返回即将被调用方法/构造方法的参数列表
     *
     * @return the parameter values, as an array
     *
     * @exception IllegalStateException 发生异常时抛出.
     */
    public Object[] getParameters();

    /**
     * 设置即将被调用的方法/构造方法的参数值
     * 
     * @param params the parameter values, as an array
     */
    public void setParameters(Object[] params);

    /**
     * 允许拦截器通过调用链中的另一个拦截器，业务方法和/或webservices上下文来检索或更新与调用相关联的数据
     * 
     * @return the context data, as a map
     */
    public Map<String, Object> getContextData();

    /**
     * 继续到拦截器链中的下一个拦截器。对于around-invoke或around-timeout拦截器方法，调用链中最后一个拦截器方法会导致调用目标类方法
     * 
     * @return the return value of the next method in the chain
     */
    public Object proceed() throws Exception;

} 
